<?
class SecurityController extends Zend_Controller_Action
{


    public function init()
    {

        $this->_helper->layout()->setLayout('index-layout');
        $usersesion = new \Zend_Session_Namespace("usersession");
        if (!$usersesion->user_id) {
            $this->_redirect("/");

        }


    }

    public function indexAction()
    {
        $userManager = new \Managers\Users();
        $usersesion = new \Zend_Session_Namespace("usersession");
        $this->view->userinfo = $userManager->infoShow($usersesion->user_id);

    }

    public function changepasswordAction()
    {
        $usersesion = new \Zend_Session_Namespace("usersession");
        $usr = new \Managers\Users();
        $pas=$this->_getParam("newpas1");
        $usrid=$usersesion->user_id;
        if($usr->isok($usersesion->user_id, $this->_getParam("pasolld"))=="inline"){

        if ($this->_getParam("newpas2") == $this->_getParam("newpas1")) {

            $usr->setPas($usrid,$pas );
            $this->_redirect("/security/?ok");
        }

        }
        $this->_redirect("/security/?fail");


    }
    public  function updateAction(){
        $id=$this->_getParam('id');
        $phone=$this->_getParam('phone');
        $address=$this->_getParam('address');
        $name=$this->_getParam('name');
        $login=$this->_getParam('login');


        $usr=new \Managers\Users();
        $usr->updateInfo($id,$phone,$address,$name,$login);
        $this->_redirect("/security/?fail");
        
    }

    public function resetpasswordAction(){
//            $usersession = new \Zend_Session_Namespace("usersession");
//        $udb=new \Managers\Users();
//
//        $res=$udb->($usersession->usr['id']);
//        print '<pre>';
//        print_r($res);
//        print '</pre>';
//        die;
//            if($usersesion->user_id){}
        $sequrity= new Managers\Security();
        $pas=$sequrity->generate_password(rand(6,16));
        $usdb= new \Managers\Users();
        $user_id=$usdb->getIdByEmail($this->_getParam("email"));
        $usdb->setPas($user_id,$pas);

        $this->view->password=$pas;


    }

}